package com.example.demo;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.ApplicationContext;

import java.util.Arrays;

@SpringBootApplication
@EnableCaching
@MapperScan("com.example.demo.dao")
public class DemoApplication implements CommandLineRunner {

	@Autowired
	ApplicationContext applicationContext;

	public static void main(String[] args) {
		SpringApplication.run(DemoApplication.class, args);

//		Student stur = new Student();
//		stur.setName("tom");
//		stur.setAge(19);
//		System.out.println(stur);

	}

	@Override
	public void run(String... args) throws Exception {
		// springboot 加载对象完成之后 调用方法；
//		Student stue = applicationContext.getBean(Student.class);
//		System.out.println(stue);

		String[] strs = applicationContext.getBeanDefinitionNames();
		System.out.println(strs.length);
//		Arrays.asList(strs).forEach(System.out::println);
		Arrays.asList(strs).forEach(item -> System.out.println(item + ":::" + applicationContext.getBean(item)));

	}
}
